import Vue from 'vue'
import FastClick from 'fastclick'
import VueRouter from 'vue-router'
import App from './App'
import store from "./store/store.js"
import router from "./router/index.js"
import VueScroller from 'vue-scroller'
import {dateFormat, ToastPlugin, LoadingPlugin} from 'vux'
import {alertY} from './components/alertY/alertPlugin.js';
import {toastY} from './components/toastY';
import {pickerY} from './components/picker/index';

import "./css/reset.css"

FastClick.attach(document.body)
Vue.use(VueScroller)
Vue.use(VueRouter)
Vue.use(ToastPlugin)
Vue.use(LoadingPlugin)
Vue.use(alertY)
Vue.use(toastY)
Vue.use(pickerY)

window.vToast = (v) => {
  Vue.$vux.toast.show({
    type: "text",
    position: "middle",
    text: v
  })
}

window.vLoading = {
  show(v){
    Vue.$vux.loading.show({
      text: v
    })
  },
  hide(){
    Vue.$vux.loading.hide()
  }
}

window.isBack = false;

window.goBack = () => {
  window.isBack = true;
  window.history.back();
}

Vue.filter("arrTOString", v => v.join(","));
Vue.filter("dateFormat", v => dateFormat(new Date(v), "YYYY-MM-DD HH:mm"));
Vue.filter("dateFormat2", v => dateFormat(new Date(v), "YYYY-MM-DD"));

Vue.prototype.$confirmY = (t, call) => {
  Vue.prototype._alertY.showAlert({
    content: t,
    onTap(v){
      call(v)
    }
  });
};
Vue.prototype.$alertY = (t, call) => {
  Vue.prototype._alertY.showAlert({
    buttons: ['确认'],
    content: t,
    onTap(v){
      call()
    }
  });
};

Vue.config.productionTip = false

new Vue({
  router,
  store,
  watch: {
    '$route': function () {
      if (window.isBack) {
        this.$store.commit("_slideIn", "slide-right-enter");
        this.$store.commit("_slideIn2", "slide-right-enter");
        this.$store.commit("_slideOut", "slide-left-leave");
        window.isBack = false;
      } else {
        this.$store.commit("_slideIn", "slide-left-enter");
        this.$store.commit("_slideIn2", "slide-left-enter");
        this.$store.commit("_slideOut", "slide-right-leave");
      }
    }
  },
  render: h => h(App)
}).$mount('#app-box')


